<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px"
			class="queryForms">
			<el-form-item label="零组件名称" prop="partName">
				<el-input v-model="queryParams.partName" placeholder="请输入零组件名称" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="编号" prop="recordNumber">
				<el-input v-model="queryParams.recordNumber" placeholder="请输入编号" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="送检人" prop="createBy">
				<el-input v-model="queryParams.createBy" placeholder="请输入送检人" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="返修任务单" prop="repairNumber">
				<el-input v-model="queryParams.repairNumber" placeholder="请输入返修任务单" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="送检时间" prop="inspectDate">
				<el-date-picker v-model="queryParams.inspectDate" type="date" placeholder="选择日期"
					value-format="yyyy-MM-dd HH-mm-ss"></el-date-picker>
			</el-form-item>
			<el-form-item label="产品型号" prop="productModel">
				<el-input v-model="queryParams.productModel" placeholder="请输入产品型号" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="零组件图号" prop="partFigure">
				<el-input v-model="queryParams.partFigure" placeholder="请输入零组件图号" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="检验状态" prop="inspectStatus">
				<el-select v-model="queryParams.inspectStatus" placeholder="请选择">
					<el-option v-for="dict in dict.type.inspect_status" :key="dict.value" :label="dict.label"
						:value="dict.value"> </el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>
		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="primary" icon="el-icon-plus" size="mini" :disabled="multiple" @click="handleAdd"
					v-hasPermi="['quality:stock:sentrance:exam']">检验</el-button>
			</el-col>
			<CreateForm :ids="ids" :rows="rows" formtype="t_quality_stock_sentrance" />
			<right-toolbar menuNames="sentrance48" @changeTableData="changeTableData" :showSearch.sync="showSearch"
				@queryTable="handleQuery" :columns.sync="columns" perm="quality:stock:sentrance:index"></right-toolbar>
		</el-row>
		<!--  -->
		<div :class="sidebar.opened && eleTabTop <= 85 ? 'eleTab' : !sidebar.opened && eleTabTop <= 85 ? 'eleTabs' : ''"
			class="informationTab" ref="eleTab">
			<el-table @expand-change="handleExpandChange" :key="treetablekey" lazy :load="loadListDes"
				:row-class-name="row_class_name" @mousedown.native="mousedownTable" @row-click="row_click"
				@cell-mouse-enter="cell_mouse_enter" @cell-mouse-leave="cell_mouse_leave" @mouseup.native="mouseupTable"
				@mouseleave.native="mouseupTable" ref="table" v-loading="loading" :data="SentranceList"
				@selection-change="handleSelectionChange" row-key="id"
				:tree-props="{ children: 'children', hasChildren: 'hasChildren' }" border height="100%">
				<el-table-column type="selection" width="55" align="center" />
				<el-table-column label="序号" align="center" type="index" width="55">
					           <template slot-scope="scope">
						<div>{{ scope.row.sort }}</div>
						           
					</template>
				</el-table-column>
				<el-table-column label="编号" prop="recordNumber" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[0].visible" />
				<!-- <el-table-column label="编号" prop="serialNumber" min-width="150" :show-overflow-tooltip="true" v-if="columns[1].visible" /> -->
				<el-table-column label="送检人" prop="createBy" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[2].visible" />
				<el-table-column label="送检时间" prop="inspectDate" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[3].visible" />
				<el-table-column label="返修任务单" prop="repairNumber" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[4].visible" />
				<el-table-column label="检验状态" prop="inspectStatus" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[13].visible">
					<template slot-scope="scope">
						<dict-tag :options="dict.type.inspect_status" :value="scope.row.inspectStatus" />
					</template>
				</el-table-column>
				<el-table-column label="供方" prop="supplier" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[5].visible" />
				<el-table-column label="工艺通知单" prop="processNumber" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[6].visible" />
				<el-table-column label="生产批次(3B)" prop="productionBatch" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[7].visible" />
				<el-table-column label="产品型号" prop="productModel" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[8].visible" />
				<el-table-column label="零组件名称" prop="partName" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[9].visible" />
				<el-table-column label="零组件图号" prop="partFigure" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[10].visible" />
				<el-table-column label="需求数" prop="partQuantity" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[11].visible" />
				<el-table-column label="合格证号" prop="certificateNumber" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[12].visible">
					<template slot-scope="scope" v-if="!scope.row.hasChildren">
						<el-input v-model="scope.row.certificateNumber" placeholder="请输入合格证号"
							@change="changeEdit(scope.row)" maxlength="20" />
					</template>
				</el-table-column>

				<el-table-column label="操作" class-name="small-padding fixed-width" width="180px" fixed="right">
					<template slot-scope="scope">
						<section v-if="scope.row.hasChildren">
							<el-button size="mini" type="text" icon="el-icon-wallet" @click="handleHG(scope.row)"
								v-hasPermi="['quality:stock:sentrance:HG']">合格证</el-button>
							<el-button size="mini" type="text" icon="el-icon-wallet" @click="handleAnnex(scope.row)"
								v-hasPermi="['quality:stock:sentrance:annex']">附件</el-button>
						</section>
						<section v-else>
							<el-button v-show="scope.row.inspectStatus == '7'" size="mini" type="text"
								icon="el-icon-edit" @click="handleExam(scope.row)"
								v-hasPermi="['quality:stock:sentrance:exam']">检验</el-button>
							<el-button size="mini" type="text" icon="el-icon-wallet" @click="handleAnnex2(scope.row)"
								v-hasPermi="['quality:stock:sentrance:annex2']">附件</el-button>
							<el-button v-show="scope.row.inspectStatus != '7'" size="mini" type="text"
								icon="el-icon-edit" @click="handleInfo(scope.row)"
								v-hasPermi="['quality:stock:sentrance:info']">详情</el-button>
						</section>
					</template>
				</el-table-column>
			</el-table>
		</div>

		<pagination menuNames="Pagination51" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
			:limit.sync="queryParams.pageSize" @pagination="getList" />

		<!-- 添加或修改发票对话框 -->
		<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body v-dialogDrag>
			<el-form ref="form" class="add-form2" :model="form" :rules="rules" label-width="120px" :disabled="disabled">
				<div class="add-mid-title">检验项目</div>
				<el-form-item label="外观" prop="appearance">
					<el-radio v-model="form.appearance" label="0">合格</el-radio>
					<el-radio v-model="form.appearance" label="1">不合格</el-radio>
				</el-form-item>
				<el-form-item label="镀层" prop="claddingMaterial">
					<el-radio v-model="form.claddingMaterial" label="0">有</el-radio>
					<el-radio v-model="form.claddingMaterial" label="1">无</el-radio>
				</el-form-item>
				<el-form-item label="规格型号" prop="specificationModel">
					<el-radio v-model="form.specificationModel" label="0">一致</el-radio>
					<el-radio v-model="form.specificationModel" label="1">不一致</el-radio>
				</el-form-item>
				<el-form-item label="数量" prop="quantity">
					<el-radio v-model="form.quantity" label="0">一致</el-radio>
					<el-radio v-model="form.quantity" label="1">不一致</el-radio>
				</el-form-item>
				<el-form-item label="合格证明" prop="qualification">
					<el-radio v-model="form.qualification" label="0">有</el-radio>
					<el-radio v-model="form.qualification" label="1">无</el-radio>
				</el-form-item>
				<el-form-item label="其他" prop="otherDescription" style="width: 100%">
					<el-input type="textarea" v-model="form.otherDescription" placeholder="请输入其他" maxlength="100"
						show-word-limit />
				</el-form-item>
				<div class="add-mid-title">检验结果</div>
				<el-form-item label="检验方式" prop="inspectionMethod">
					<el-select v-model="form.inspectionMethod" placeholder="请选择">
						<el-option v-for="dict in dict.type.inspection_method" :key="dict.value" :label="dict.label"
							:value="dict.value"> </el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="数量" prop="inspectionQuantity" v-if="showNums">
					<el-input-number v-model="form.inspectionQuantity" placeholder="请输入数量" :min="0" :max="99999999"
						:precision="0" />
				</el-form-item>
				<el-form-item label="检验员" prop="checkoutId">
					<el-select v-model="form.checkoutId" placeholder="请选择" @change="changeUser" filterable>
						<el-option v-for="item in userList" :key="item.userId" :label="item.nickName"
							:value="item.userId">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="不合格处置情况" prop="disposalSituation" style="width: 100%">
					<el-input type="textarea" v-model="form.disposalSituation" placeholder="请输入不合格处置情况" maxlength="100"
						show-word-limit />
				</el-form-item>
				<el-form-item label="备注" prop="remark" style="width: 100%">
					<el-input type="textarea" v-model="form.remark" placeholder="请输入备注" maxlength="100"
						show-word-limit />
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer" v-if="showTitles">
				<el-button type="primary" @click="submitForm(3)">合格</el-button>
				<el-button type="primary" @click="submitForm(4)">不合格</el-button>
				<el-button type="primary" @click="submitForm(5)">让步接收</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import { submitSentranceBatch, listSentrance, listSentranceChild, getSentrance, delSentrance, submitSentrance, repairMaterialPart } from "@/api/quality/stock/sentrance"
import { mapGetters } from "vuex"
import { getUserList, getcolumn } from "@/api/selectList"
import searchStateMixin from '@/layout/mixin/searchStateMixin.js'
import CreateForm from "@/views/components/CreateForm"
export default {
	name: "Sentrance",
	dicts: ["inspect_status", "inspection_method"],
	components: { CreateForm },
	mixins: [searchStateMixin],
	computed: {
		...mapGetters(["sidebar", "name", "id"])
	},
	data() {
		return {
			showTitles: true,
			tableTreeRefreshTool: {}, // 用于存储 resolve 方法和展开状态
			isMousedownTable: false, //是否按下表格
			currentEnterRow: null, //当前移入的行数据
			showNums: false,
			eleTabTop: 0, //表格容器距浏览器顶部距离
			testval: undefined,
			// 遮罩层
			loading: true,
			// 选中数组
			ids: [],
			rows: [],
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			// 显示搜索条件
			showSearch: true,
			// 总条数
			total: 0,
			// 设备保养计划表格数据
			SentranceList: [],
			// 弹出层标题
			title: "",
			// 是否显示弹出层
			open: false,
			// 查询参数
			queryParams: {
				recordNumber: undefined,
				pageNum: 1,
				pageSize: 10,
				deviceName: undefined,
				inspectStatus: undefined,
				applyTime: undefined,
				repairNumber: undefined,
				inspectDate: undefined,
				productModel: undefined,
				partFigure: undefined,
				inspectStatus: undefined,
				createBy: undefined,
				partName: undefined
			},
			// 表单参数
			form: {},
			// 表单校验
			rules: {
				appearance: [{ required: true, message: "请选择外观", trigger: "change" }],
				claddingMaterial: [{ required: true, message: "请选择镀层", trigger: "change" }],
				specificationModel: [{ required: true, message: "请选择规格型号", trigger: "change" }],
				qualification: [{ required: true, message: "请选择合格证明", trigger: "change" }],
				inspectionQuantity: [{ required: true, message: "请输入数量", trigger: "blur" }]
			},
			deviceList: [],
			// 更新树刷新
			treeMap: new Map(),
			// 审批数据
			openApprove: false,
			approveRow: undefined,
			// 生产计划
			isOne: false,
			disabled: false,
			// 审批流程
			// openRecords: false,
			approveRecord: [],
			treetablekey: Math.random(),
			disabled: false,
			// 用户列表
			userList: [],
			columns: [
				{ key: 0, label: "记录编号", visible: true },
				{ key: 1, label: "编号", visible: true },
				{ key: 2, label: "送检人", visible: true },
				{ key: 3, label: "送检时间", visible: true },
				{ key: 4, label: "返修任务单", visible: true },
				{ key: 5, label: "供方", visible: true },
				{ key: 6, label: "工艺通知单", visible: true },
				{ key: 7, label: "生产批次(3B)", visible: true },
				{ key: 8, label: "产品型号", visible: true },
				{ key: 9, label: "零组件名称", visible: true },
				{ key: 10, label: "零组件图号", visible: true },
				{ key: 11, label: "需求数", visible: true },
				{ key: 12, label: "合格证号", visible: true },
				{ key: 13, label: "检验状态", visible: true }
			]
		}
	},
	created() {
		// 如果是页面刷新，重置查询
		if (window.performance && performance.navigation.type === performance.navigation.TYPE_RELOAD) {
			this.resetForm("queryForm")
			// 清除URL中的查询参数（不刷新页面）
			window.history.replaceState({}, document.title, window.location.pathname)
		}
		this.getUserList()
		// this.getSize()
	},

	mounted() {
		// 滚动条的获取
		this.handleScrollx()
		window.addEventListener("scroll", this.handleScrollx, true)
	},
	watch: {
		"$route.query": {
			handler(newQuery, oldQuery) {
				if (newQuery.queryData) {
					if (Object.keys(newQuery.queryData).length === 0) {
						this.resetQuerys()
					} else {
						this.queryParams = { ...this.queryParams, ...JSON.parse(newQuery.queryData) }
					}
				}
				this.getSize()
			},
			immediate: true, // 立即执行一次
			deep: true // 深度监听
		}
	},
	activated() {
		// this.getSize()
		//获取表格容器距页面头部的距离
		this.handleScrollx()
	},
	destroyed() {
		window.removeEventListener("scroll", this.handleScrollx, true)
	},
	methods: {
		// 关闭所有展开的行
		closeAllExpansions() {
			this.SentranceList.forEach(row => {
				this.$refs.table.toggleRowExpansion(row, false)
			})
			if (this.$refs.table) {
				this.$refs.table.clearSelection()
			}

			this.getList()
		},
		getSize() {
			getcolumn({ pageName: "Pagination51" }).then(response => {
				this.queryParams.pageSize = response.data.length ? (response.data[0].limit ? response.data[0].limit : 10) : 10
				this.getList()
			})
		},
		doesEveryElementContain(array, charToCheck) {
			return array.every(element => element + "".indexOf(charToCheck) !== -1)
		},
		handleAdd() {
			this.reset()
			// 获取子级数据
			let curs = this.ids.filter(item => {
				return String(item).indexOf("c") == 0
			})
			let flag = this.rows.every(item => item.inspectStatus == "7")
			if (this.ids.length != curs.length) {
				this.$modal.msgError("请选择子级记录")
			} else if (!flag) {
				this.$modal.msgError("只能检验未检验的数据")
			} else {
				this.reset()
				this.title = "检验"
				this.showNums = false
				this.showTitles = true
				this.open = true
			}
		},
		handleHG(row) {
			this.$router.push({
				path: "/attachment/attachmentUpload",
				query: {
					TableId: row.repairMaterialId,
					typeId: 39,
					perm: "quality:stock:sentrance:HG",
					// queryParams: JSON.stringify(this.queryParams),
					paths: "/quality/stock/sentrance",
				}
			})
		},
		//获取表格容器距页面头部的距离
		handleScrollx() {
			this.eleTabTop = this.$refs.eleTab.getBoundingClientRect().top
		},
		// 获取用户下拉选
		getUserList() {
			getUserList().then(res => {
				this.userList = res.rows
			})
		},
		changeUser() {
			this.userList.forEach(item => {
				if (item.userId == this.form.checkoutId) {
					this.form.checkoutName = item.nickName
				}
			})
		},
		/** 查询设备保养计划列表 */
		getList() {
			this.loading = true
			listSentrance(this.queryParams).then(response => {
				this.SentranceList = response.rows
				this.SentranceList.forEach((item, index) => {
					item.hasChildren = true
					item.sort = index + 1
					// this.$refs.table.toggleRowExpansion(item, false);
				})
				this.total = response.total
				this.loading = false
			})
		},
		refreshLoadTree(parentId) {
			const { tree, treeNode, resolve } = this.treeMap.get(parentId)
			this.loadListDes(tree, treeNode, resolve) // 重新加载子级数据
			this.$refs.table.clearSelection()
		},

		// 展开/收起时触发
		handleExpandChange(row, expanded) {
			const curr = this.tableTreeRefreshTool[row.id]
			if (!curr) return
			curr.expandCount++
			if (expanded && curr.expandCount > 1 && !curr.prevStatus) {
				let queryParams = JSON.parse(JSON.stringify(this.queryParams))
				delete queryParams.pageSize
				delete queryParams.pageNum
				listSentranceChild({
					id: row.id,
					...queryParams
				}).then(res => {
					res.rows.forEach((item, index) => {
						// 父子id会冲突
						item.id = "c" + item.id
						item.sort = index + 1
					})
					curr.resolve(res.rows)
				})
			}
			curr.prevStatus = expanded
		},
		// 获取列表详情
		async loadListDes(tree, treeNode, resolve) {
			if (!this.treeMap.has(tree.id)) {
				this.treeMap.set(tree.id, { tree: tree, treeNode, resolve })
			}
			this.tableTreeRefreshTool[tree.id] = {
				resolve,
				expandCount: 0, // 展开次数
				prevStatus: false // 上一次的展开状态
			}
			let queryParams = JSON.parse(JSON.stringify(this.queryParams))
			delete queryParams.pageSize
			delete queryParams.pageNum
			let data = {
				id: tree.id,
				...queryParams
			}
			let ret = await listSentranceChild(data)
			tree.hasChildren = ret.rows.length > 0
			tree.children = ret.rows

			if (ret.rows.length == 0) {
				resolve([]) // 确保返回空数组
				this.$set(this.$refs.table.store.states.lazyTreeNodeMap, tree.id, [])
			} else {
				ret.rows.forEach((item, index) => {
					// 父子id会冲突
					item.id = "c" + item.id
					item.sort = index + 1
				})
				resolve(ret.rows)
			}
		},
		// 取消按钮
		cancel() {
			this.open = false
			this.reset()
		},
		// 表单重置
		reset() {
			this.disabled = false
			this.form = {
				id: undefined,
				appearance: "0",
				claddingMaterial: "0",
				specificationModel: "0",
				quantity: "0",
				qualification: "0",
				otherDescription: undefined,
				inspectionMethod: "2",
				inspectionQuantity: undefined,
				checkoutId: this.id,
				checkoutName: this.name,
				disposalSituation: undefined,
				remark: undefined
			}
			this.resetForm("form")
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1
			this.saveSearchState()
			this.getList()
			this.treetablekey = Math.random()
		},
		resetQuery() {
			this.queryParams = {
				recordNumber: undefined,
				pageNum: 1,
				pageSize: this.queryParams.pageSize,
				deviceName: undefined,
				inspectStatus: undefined,
				applyTime: undefined,
				repairNumber: undefined,
				inspectDate: undefined,
				productModel: undefined,
				partFigure: undefined,
				inspectStatus: undefined,
				createBy: undefined,
				partName: undefined
			}
			this.clearSearchCache()
			this.resetForm("queryForm")
		},
		/** 重置按钮操作 */
		resetQuery() {
			this.queryParams = {
				recordNumber: undefined,
				pageNum: 1,
				pageSize: this.queryParams.pageSize,
				deviceName: undefined,
				inspectStatus: undefined,
				applyTime: undefined,
				repairNumber: undefined,
				inspectDate: undefined,
				productModel: undefined,
				partFigure: undefined,
				inspectStatus: undefined,
				createBy: undefined,
				partName: undefined
			}
			this.resetForm("queryForm")
			this.handleQuery()
		},
		// 表格按下
		mousedownTable(event) {
			const target = event.target
			// 判断target的class属性确定是否点击在复选框上
			if (target.classList.contains("el-checkbox__inner")) {
				this.currentEnterRow && this.$refs.table.toggleRowSelection(this.currentEnterRow)
				this.isMousedownTable = true
			}
		},
		// 单击表格行
		row_click(row, column, event) {
			if (column && column.label == "操作") {
				return
			} else {
				this.$refs.table.toggleRowSelection(row)
				let flag = this.ids.some(item => item == row.id)
				if (row.hasChildren) {
					row.children.forEach(items => {
						if (flag) {
							this.$refs.table.toggleRowSelection(items, true)
						}
					})
				}
			}
		},
		changeTableData() {
			this.$nextTick(() => {
				this.$refs.table.doLayout()
			})
		},

		// 进入单元格
		cell_mouse_enter(row, column, cell, event) {
			this.isMousedownTable && this.$refs.table.toggleRowSelection(row)
			this.currentEnterRow = row
		},
		// 离开单元格
		cell_mouse_leave(row, column, cell, event) {
			this.currentEnterRow = null
		},
		// 鼠标弹起或者离开表格
		mouseupTable(d) {
			this.isMousedownTable = false
		},
		// 表格每行样式
		row_class_name({ row, rowIndex }) {
			return this.rows.find(v => v.id == row.id) ? "selected" : ""
		},
		// 多选框选中数据
		handleSelectionChange(selection) {
			this.ids = selection.map(item => item.id)
			this.rows = selection
			this.single = selection.length !== 1
			this.multiple = !selection.length
		},
		// 检验
		handleExam(row) {
			this.showNums = true
			this.reset()
			this.title = "检验"
			let id = row.id.replace("c", "")
			getSentrance(id).then(response => {
				this.form = response.data
				this.form.checkoutId = this.form.checkoutId ? this.form.checkoutId : this.id
				this.form.checkoutName = this.form.checkoutName ? this.form.checkoutName : this.name
				this.open = true
				this.showTitles = true
			})
		},
		// 详情
		handleInfo(row) {
			this.reset()
			this.title = "详情"
			let id = row.id.replace("c", "")
			getSentrance(id).then(response => {
				this.disabled = true
				this.form = response.data
				this.open = true
				this.showTitles = false
			})
		},
		/** 提交检验 */
		submitForm(val) {
			this.$refs["form"].validate(valid => {
				if (valid) {
					const loading = this.$loading({
						lock: true,
						text: "Loading",
						spinner: "el-icon-loading",
						background: "rgba(0, 0, 0, 0.7)"
					})
					this.form.inspectStatus = val
					if (this.showNums) {
						submitSentrance(this.form).then(response => {
							this.$modal.msgSuccess("操作成功")
							this.open = false
							this.refreshLoadTree(this.form.repairMaterialInspectId) // 刷新子级数据
							localStorage.setItem("todoMessage", "sentrance12")
							// this.closeAllExpansions()
							loading.close()
						}).finally(res => {
							loading.close()
						})
					} else {
						let idData = []
						this.ids.forEach(item => {
							idData.push(item.replace("c", ""))
						})
						this.form.idList = idData
						submitSentranceBatch(this.form).then(res => {
							this.$modal.msgSuccess("操作成功")
							this.open = false
							this.$refs.table.clearSelection()
							// this.getList()
							this.closeAllExpansions()
							localStorage.setItem("todoMessage", "sentrance13")
							loading.close()
						}).finally(res => {
							loading.close()
						})
					}
				}
			})
		},
		// 提交修改
		changeEdit(row) {
			let data = {
				id: row.id.replace("c", ""),
				certificateNumber: row.certificateNumber || undefined
			}
			repairMaterialPart(data).then(response => {
				this.$modal.msgSuccess("操作成功")
			})
		},
		// 附件
		handleAnnex(row) {
			this.$router.push({
				path: "/attachment/attachmentUpload",
				query: {
					TableId: row.id,
					typeId: 26,
					perm: "quality:stock:sentrance:annex",
					// queryParams: JSON.stringify(this.queryParams),
					paths: "/quality/stock/sentrance",
				}
			})
		},
		handleAnnex2(row) {
			let id = row.id.replace("c", "")
			this.$router.push({
				path: "/attachment/attachmentUpload",
				query: {
					TableId: id,
					typeId: 27,
					perm: "quality:stock:sentrance:annex2",
					// queryParams: JSON.stringify(this.queryParams),
					paths: "/quality/stock/sentrance",
				}
			})
		},

		checkIds() {
			// 判断ids
			if (this.ids.length == 0) {
				this.$modal.msg("请选择产品")
				return false
			} else {
				// 判断是否选中了父级返修任务
				let checkp = this.rows.find(item => {
					return Number(item.id) > 0
				})
				if (checkp) {
					this.$modal.msg("只能选择子类产品")
					return false
				}
			}
			let ids = this.ids.map(item => {
				return item.replace("c", "")
			})
			return ids
		},
		// 更新树
		refreshTree() {
			this.treeMap.forEach((item, idx) => {
				this.loadListDes({ id: idx }, item.treeNode, item.resolve)
			})
		},
		// 下发
		handleDown(row) {
			let ids = this.checkIds()
			if (!ids) {
				return false
			}
			// 判断状态
			let checkrows = false
			this.rows.forEach(item => {
				if (item.inspectStatus != "1" && item.inspectStatus != "3" && item.inspectStatus != "5") {
					checkrows = true
				}
			})
			if (checkrows) {
				this.$modal.msg("只有入库、合格、让步接收可以下发")
				return false
			}
			this.reset()
			this.form.ids = ids
			this.open = true
			this.title = "下发"
		}
	}
}
</script>

<style lang="scss" scoped>
::v-deep .el-table__fixed-header-wrapper .fixed-width {
	width: 180px !important;
}

.add-mid-title {
	width: 100%;
	margin: 20px 0 10px 0;
}
</style>
